/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.base;

import picounit.features.base.exception.MissingClassFile;

class ClassFindingCodeVisitor implements CodeVisitor {
	private final String className;

	private byte[] byteCode;

	public ClassFindingCodeVisitor(String className) {
		this.className = className;
	}

	public Status visit(Code code) {
		byteCode = code.findClass(className);

		return byteCode != null ? Status.TerminalSuccess : Status.Failure;
	}

	public byte[] byteCode() {
		if (byteCode != null) {
			return byteCode;
		}

		throw new MissingClassFile("Could not find byte code for: " + className);
	}
}